<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>06自定有JS对象</title>
</head>
<body>
<table border="1">
    <tr>
        <th>商品名称</th>
        <th>商品价格</th>
        <th>商品库存</th>
    </tr>
</table>
<script>
    let arr=[
        {name:'小米',price:1999,stock:130},
        {name:'华为',price:1879,stock:100},
        {name:'苹果',price:4799,stock:340},
        {name:'oppo',price:1899,stock:40}
    ];
    let table=document.querySelector('table');
    for(let i=0;i<arr.length;i++){
        let tr=document.createElement('tr');
        for(let key in arr[i]){
            let td=document.createElement('td');
            td.innerHTML=arr[i][key];
            tr.append(td);
        }
        table.append(tr);
    }

    //1.创建一个自带属性与方法的js对象
    let p1 ={
        name:'张三',
        age:18,
        sex:'男',
        say:function(){
            console.log('我是'+this.name+',今年'+this.age+'岁');
        }
    }
    console.log(p1);
    p1.say();

    //2.创建一个空对象，再给其动态添加属性与方法
    let p2={};
    p2.name='李四';
    p2.age=19;
    p2.sex='女';
    p2.say=function(){
        console.log('我是'+this.name+',今年'+this.age+'岁');
    }
    console.log(p2);
    p2.say();
</script>
</body>
</html>